/**
 * Created by houyong on 16-8-22.
 */
public class GenericArray<T> {
    private  Object[] array;
    public GenericArray(int sz){
        array = new  Object[sz];
    }
    public void put(int index,T item){
        array[index] = item;
    }
    public T get(int index){
        return (T) array[index];
    }
    public  T[] rep(){
        return  (T[])array;
    }

    public static <T> T[] rep(T[] item){
        return (T[]) item;
    }
    public static void main(String[] args) {
        GenericArray<Integer> genericArray = new GenericArray<Integer>(10);
        for (int i =0 ;i<10;i++){
            genericArray.put(i,i);
        }
        for (int i=0;i<10;i++){
            System.out.println(genericArray.get(i));
        }
        try{
            Object[] a =  genericArray.rep();
            for (int i=0;i<10;i++){
                System.out.println("args = [" + a[i] + "]");;
            }
            System.out.printf(a.toString());
            Object[] aa = genericArray.rep(a);
            for (int i=0;i<10;i++){
                System.out.println("args = [" + aa[i] + "]");;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
